package com.ty.service.impl;

import java.util.List;

import com.ty.dao.UserDao;
import com.ty.dao.impl.UserDaoImpl;
import com.ty.entity.User;
import com.ty.service.UserService;

/**
 * 用户服务实现类
 */
public class UserServiceImpl implements UserService {
    private final UserDao userDao = new UserDaoImpl();

    @Override
    public User login(String account, String password) {
        if (account == null || password == null) {
            return null;
        }
        return userDao.findByAccountAndPassword(account, password);
    }

    @Override
    public boolean addUser(String username, String account, String password, int permission) {
        if (username == null || account == null || password == null) {
            return false;
        }
        User user = new User(username, account, password, permission);
        return userDao.add(user) > 0;
    }

    @Override
    public boolean updateUser(int id, String username, String account, String password, int permission) {
        User user = new User(username, account, password, permission);
        user.setId(id);
        return userDao.update(user) > 0;
    }

    @Override
    public boolean deleteUser(int id) {
        return userDao.delete(id) > 0;
    }

    @Override
    public List<User> getAllUsers() {
        return userDao.findAll();
    }

    @Override
    public List<User> getUsersByUsername(String username) {
        return userDao.findByUsername(username);
    }
} 